<?php
namespace app\api\controller\system;
use app\admin\model\system\About;
use app\admin\model\system\Slide;
use app\common\controller\ApiBase;
use app\common\annotation\ApiNodeAnnotation;
/**
 * @ApiNodeAnnotation(
 *     title="系统Api",
 *      parent="default",
 *     is_release=0,
 *     auth=1,
 * )
 */
class Index extends ApiBase
{
    /**
     * @ApiNodeAnnotation(
     *     title="幻灯片列表",
     *     parent="api/system.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function slide()
    {
        $slideList = (new Slide())->limit($this->request->param("limit",6,'intval'))
            ->page($this->request->param('page',0,'intval'))
            ->where('status',1)
            ->field("id,title,url_link,photo")
            ->select();
        $this->success("success:",'',$slideList);
    }

    /**
     * @ApiNodeAnnotation(
     *     title="站点信息",
     *     parent="api/system.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function website()
    {
        $website = get_option("site_info");
        $this->success("success:",'',$website);
    }

    /**
     * @ApiNodeAnnotation(
     *     title="站点信息",
     *     parent="api/system.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function system()
    {
        $system_setting = get_option("system_setting");
        $this->success("success:",'',$system_setting);
    }

    /**
     * @ApiNodeAnnotation(
     *     title="站点加系统信息",
     *     parent="api/system.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function website_system()
    {
        $website = get_option("site_info");
        $system_setting = get_option("system_setting");
        $new_info = array_merge($website,$system_setting);

        $new_info['logo'] = isset($new_info['photo'])? _get_image_preview_url($new_info['photo']):'';
        $new_info['qqCode'] = isset($new_info['qqCode']) ?_get_image_preview_url($new_info['qqCode']):'';
        $new_info['wechatCode'] = isset($new_info['wechatCode'])?_get_image_preview_url($new_info['wechatCode']):'';

        if(strpos($new_info['logo'],'http') !== 0 || strpos($new_info['logo'],'/') === 0)
        {
            unset($new_info['photo']);
            $new_info['logo'] = _get_domain().DIRECTORY_SEPARATOR.$new_info['logo'];
            $new_info['logo'] = str_replace("//uploads","/uploads", $new_info['logo']);
        }

        if(strpos($new_info['qqCode'],'https') !==0 || strpos($new_info['qqCode'],'/') === 0)
        {
            $new_info['qqCode'] = _get_domain().DIRECTORY_SEPARATOR.$new_info['qqCode'];
            $new_info['qqCode'] = str_replace("//uploads","/uploads", $new_info['qqCode']);
        }

        if(strpos($new_info['wechatCode'],'https') !==0|| strpos($new_info['wechatCode'],'/') ==0)
        {

            $new_info['wechatCode'] = _get_domain().DIRECTORY_SEPARATOR.$new_info['wechatCode'];
            $new_info['wechatCode'] = str_replace("//uploads","/uploads", $new_info['wechatCode']);
        }
        $this->success("success:",'',$new_info);
    }

    /**
     * @ApiNodeAnnotation(
     *     title="关于我们",
     *     parent="api/system.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function about()
    {
        $about = About::order("update_time desc")->find();
        $this->success("success:",'',$about);
    }

}